package gui.panels;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.SSHConnectionProxy;
import net.miginfocom.swing.MigLayout;

public class LeftMenu extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1223902524869162703L;

	private Customizer customizer;

	private Logger logger;

	public void setCustomizer(Customizer customizer) {
		this.customizer = customizer;
	}

	/**
	 * Create the panel.
	 */
	public LeftMenu() {
		setLayout(new MigLayout("wrap 1"));
		setBorder(BorderFactory.createTitledBorder("Menu"));
		logger = LoggerFactory.getLogger(LeftMenu.class);

		JButton btnInterfaces = new JButton("Interfaces");
		btnInterfaces.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if (customizer == null)
					return;
				if (!SSHConnectionProxy.isConnected()) {
					logger.warn("There is no active connection");
					return;
				}
				customizer.setPane(new gui.customizer.panes.Interfaces(),
						"Interfaces");
			}
		});
		add(btnInterfaces, "w 120!");

		JButton btnNetfilter = new JButton("Netfilter");
		btnNetfilter.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if (customizer == null)
					return;
				if (!SSHConnectionProxy.isConnected()) {
					logger.warn("There is no active connection");
					return;
				}
				customizer.setPane(new gui.customizer.panes.Netfilter(), "Netfilter");
			}
		});
		add(btnNetfilter, "w 120!");

//		JButton btnQos = new JButton("QoS");
//		add(btnQos, "w 120!");

		JButton btnDhcp = new JButton("DHCP");
		btnDhcp.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if (customizer == null)
					return;
				if (!SSHConnectionProxy.isConnected()) {
					logger.warn("There is no active connection");
					return;
				}
				customizer.setPane(new gui.customizer.panes.Dhcp(), "DHCP");
			}
		});
		add(btnDhcp, "w 120!");

		JButton btnLogs = new JButton("Logs");
		btnLogs.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if (customizer == null)
					return;
				if (!SSHConnectionProxy.isConnected()) {
					logger.warn("There is no active connection");
					return;
				}
				customizer.setPane(new gui.customizer.panes.Logs(), "Logs");
			}
		});
		add(btnLogs, "w 120!");

		JButton btnStatistics = new JButton("Statistics");
		btnStatistics.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				if (customizer == null)
					return;
				if (!SSHConnectionProxy.isConnected()) {
					logger.warn("There is no active connection");
					return;
				}
				customizer.setPane(new gui.customizer.panes.Statistics(), "Statistics");
			}
		});
		add(btnStatistics, "w 120!");
	}

}
